package com.liujit.bms.admin.controller;

import com.liujit.bms.admin.domain.params.BlogLabelParams;
import com.liujit.bms.admin.domain.query.BlogLabelQuery;
import com.liujit.bms.admin.domain.result.BlogLabelResult;
import com.liujit.bms.admin.service.BlogLabelService;
import com.liujit.common.domain.params.BaseParams;
import com.liujit.common.domain.result.PageBean;
import com.liujit.validator.group.AddGroup;
import com.liujit.validator.group.ModifyGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 博客标签管理接口
 * @Author liujun
 * @Date 2021-07-03 14:37:26
 */
@RequiredArgsConstructor
@Api(tags = "博客标签管理接口")
@RestController
@RequestMapping("/blog/label")
public class BlogLabelController {

    private final BlogLabelService blogLabelService;

    @ApiOperation(value = "分页查询", notes = "根据博客标签分页查询条件，分页查询博客标签列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "博客标签分页查询条件", dataType = "BlogLabelQuery", dataTypeClass = BlogLabelQuery.class, paramType = "query") })
    @GetMapping("/getPage")
    public PageBean<BlogLabelResult> getPage(BlogLabelQuery query) {
        return blogLabelService.getPage(query);
    }

    @ApiOperation(value = "添加", notes = "根据博客标签添加请求参数，添加博客标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客标签添加请求参数", dataType = "BlogLabelParams", dataTypeClass = BlogLabelParams.class, paramType = "body") })
    @PostMapping("add")
    public Boolean add(@RequestBody @Validated(AddGroup.class) BlogLabelParams params) {
        return blogLabelService.save(params);
    }

    @ApiOperation(value = "修改", notes = "根据博客标签修改请求参数，修改博客标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客标签修改请求参数", dataType = "BlogLabelParams", dataTypeClass = BlogLabelParams.class, paramType = "body") })
    @PostMapping("/modify")
    public Boolean modify(@RequestBody @Validated(ModifyGroup.class) BlogLabelParams params) {
        return blogLabelService.save(params);
    }

    @ApiOperation(value = "查询", notes = "根据博客标签id，查询博客标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "博客标签id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/get")
    public BlogLabelResult get(Long id) {
        return blogLabelService.get(id);
    }

    @ApiOperation(value = "删除", notes = "根据博客标签删除请求参数，删除博客标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客标签删除请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/del")
    public Boolean del(@RequestBody BaseParams params) {
        return blogLabelService.del(params);
    }

    @ApiOperation(value = "启用", notes = "根据博客标签启用请求参数，启用博客标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客标签启用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/enabled")
    public Boolean enabled(@RequestBody BaseParams params) {
        return blogLabelService.enabled(params);
    }

    @ApiOperation(value = "禁用", notes = "根据博客标签禁用请求参数，禁用博客标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "博客标签禁用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/disabled")
    public Boolean disabled(@RequestBody BaseParams params) {
        return blogLabelService.disabled(params);
    }

    @ApiOperation(value = "查询条数", notes = "根据博客标签名称，查询博客标签条数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "博客标签id", dataType = "Long", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "博客标签名称", dataType = "String", dataTypeClass = String.class, paramType = "query") })
    @GetMapping("/getCountByName")
    public Integer getCountByName(Long id, String name) {
        return blogLabelService.getCountByName(id, name);
    }

    @ApiOperation(value = "查询列表", notes = "查询博客标签列表")
    @GetMapping("/getList")
    public List<BlogLabelResult> getList() {
        return blogLabelService.getList();
    }
}
